package com.kaikeba.estack.web.filter;

import com.kaikeba.estack.web.ApplicationContext;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Auth xingwan
 * @Date 2020/9/10 23:50
 **/
public class ApplicationContextHolderFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        //httpServletRequest设置到holder中
        ApplicationContext.setRequest(httpServletRequest);
        filterChain.doFilter(servletRequest, servletResponse);
        ApplicationContext.clearHolder();
    }

    @Override
    public void destroy() {

    }
}
